<?php
/**
 * 用于处理用户发起新话题的请求
 *
 * @author Judas <judasnow@gmail.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */
session_start();
require_once( 'path.php' );
require_once( SOJ_ROOT.'/include/function/lib.php' );

@$request = $_POST;

try {
	$db = db_connect();
	$topic_process = new topic_process( $db , $request ) ;

	if ( !empty( $_SESSION['username'] ) ){ 
		
		@$username = $_SESSION['username'] ;

	}else{
		//允许匿名发帖，默认当然为anonymous
		$username = 'anonymous' ;	
	}	

	$topic_process->set_username( $username );
	//此处需要检查是否已经成功的保存帖子
	$topic_process->save();
	
	$_SESSION['success_message'] = 'Post new topic success.';
	$_SESSION['url'] = "/soj/php/questions/topic_list.php";
	header( 'Location:../message_handle/success_handle.php' );
	exit ;
	

}catch( Exception $e ){

	 exception_handle( $e ) ;

}
